#include "mpHttpRequestStringContent.h"
#include "mpHashUtils.h"

namespace MP{
namespace HTTP{
namespace INTERNAL{

HttpRequestStringContent::HttpRequestStringContent(const std::string& data,
                                                   const std::string & httpcontent_type)
    :_data(data)
{
    HttpRequestContent::setContentType(httpcontent_type);
}

std::string HttpRequestStringContent::getMd5(){
    std::string md5;
    if(!_data.empty()){
        MP::HashUtils::text_md5_hex(_data,md5);
    }
    return md5;
}

std::size_t HttpRequestStringContent::getContentLength() {
    return _data.size();
}

bool HttpRequestStringContent::beginWriteData(){
    return true;
}

bool HttpRequestStringContent::onWriteDataSome(std::vector<boost::asio::const_buffer>& buffers){
    //如果返回真，则表示仍有数据需要写入；
    //如果返回假，则表示当前数据写入完成后则Payload写入完毕

    buffers.push_back(boost::asio::buffer(_data));
    return false;
}

void HttpRequestStringContent::endWriteData(){

}



}   //INTERNAL
}   //HTTP
}   //MP
